home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / ipport / ping.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-15  |  4.9 KB  |  170 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Ping!!"
  5.    ClientHeight    =   5010
  6.    ClientLeft      =   1200
  7.    ClientTop       =   1500
  8.    ClientWidth     =   5745
  9.    Height          =   5415
  10.    Left            =   1140
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5010
  13.    ScaleWidth      =   5745
  14.    Top             =   1155
  15.    Width           =   5865
  16.    Begin CommandButton Command1 
  17.       Caption         =   "Ping !!"
  18.       Height          =   375
  19.       Left            =   4440
  20.       TabIndex        =   5
  21.       Top             =   240
  22.       Width           =   1215
  23.    End
  24.    Begin TextBox tResponse 
  25.       Height          =   4095
  26.       Left            =   120
  27.       MultiLine       =   -1  'True
  28.       ScrollBars      =   2  'Vertical
  29.       TabIndex        =   3
  30.       Top             =   840
  31.       Width           =   5535
  32.    End
  33.    Begin TextBox tHostAddress 
  34.       Height          =   285
  35.       Left            =   1440
  36.       TabIndex        =   2
  37.       Top             =   480
  38.       Width           =   2895
  39.    End
  40.    Begin TextBox tHostName 
  41.       Height          =   285
  42.       Left            =   1440
  43.       TabIndex        =   1
  44.       Top             =   120
  45.       Width           =   2895
  46.    End
  47.    Begin IPPORT IPPort1 
  48.       EOL             =   ""
  49.       InBufferSize    =   2048
  50.       Left            =   480
  51.       LocalPort       =   0
  52.       OutBufferSize   =   2048
  53.       Port            =   0
  54.       Top             =   0
  55.    End
  56.    Begin Label Label1 
  57.       BackStyle       =   0  'Transparent
  58.       Caption         =   "Host Address:"
  59.       Height          =   255
  60.       Index           =   1
  61.       Left            =   120
  62.       TabIndex        =   4
  63.       Top             =   480
  64.       Width           =   2175
  65.    End
  66.    Begin Label Label1 
  67.       BackStyle       =   0  'Transparent
  68.       Caption         =   "Host Name:"
  69.       Height          =   255
  70.       Index           =   0
  71.       Left            =   120
  72.       TabIndex        =   0
  73.       Top             =   150
  74.       Width           =   1815
  75.    End
  76. Sub Command1_Click ()
  77. On Error GoTo ErrorHandling:
  78. If Command1.Caption = "Stop!" Then
  79.     IPPort1.Connected = False
  80.     MousePointer = 0
  81.     Command1.Caption = "Ping!!"
  82.     Exit Sub
  83. End If
  84. IPPort1.EOL = Chr$(10)
  85. Me.MousePointer = 11
  86. 'close old connection - if any
  87. IPPort1.Connected = False
  88. If IPPort1.HostAddress = "0.0.0.0" Then
  89.     If tHostName <> "" Then
  90.         IPPort1.HostName = tHostName.Text
  91.         tHostAddress.Text = IPPort1.HostAddress
  92.     ElseIf IPPort1.HostAddress <> "" Then
  93.         IPPort1.HostAddress = tHostAddress.Text
  94.         tHostName.Text = IPPort1.HostName
  95.     Else
  96.         MsgBox "Please specify a host."
  97.         Exit Sub
  98.     End If
  99. End If
  100. IPPort1.Port = 7 'echo service
  101. 'ask for connection
  102. IPPort1.Connected = True
  103. 'wait until it is achieved
  104. Do Until IPPort1.Connected: DoEvents: Loop
  105. 'send data until disconnected
  106. msg$ = "Hello Hello"
  107. Command1.Caption = "Stop!"
  108. Do Until Not IPPort1.Connected
  109.     IPPort1.DataToSend = msg$
  110.     tResponse.SelStart = Len(tResponse.Text)
  111.     tResponse.SelText = "Sent " & Len(msg$) & " bytes: " & msg$ & "... "
  112.     'now wait a little
  113.     For i = 1 To 10000: DoEvents: Next i
  114. Exit Sub
  115. ErrorHandling:
  116.     Me.MousePointer = 0
  117.     MsgBox "Error!! " & Error$
  118.     IPPort1.Connected = False
  119.     Exit Sub
  120. End Sub
  121. Sub Form_Resize ()
  122. margin = tResponse.Left
  123. tResponse.Height = ScaleHeight - tResponse.Top - margin
  124. tResponse.Width = ScaleWidth - 2 * margin
  125. Command1.Left = ScaleWidth - Command1.Width - margin
  126. tHostName.Width = ScaleWidth - tHostName.Left - Command1.Width - 2 * margin
  127. tHostAddress.Width = ScaleWidth - tHostAddress.Left - Command1.Width - 2 * margin
  128. End Sub
  129. Sub IPPort1_Connected (StatusCode As Integer, Description As String)
  130. tResponse = ""
  131. If Description <> "OK" Then
  132.     MsgBox "Connection error: " & Description
  133.     Me.MousePointer = 0
  134. End If
  135. End Sub
  136. Sub IPPort1_DataIn (Text As String, EOL As Integer)
  137. tResponse.SelStart = Len(tResponse.Text)
  138. tResponse.SelText = "received " & Len(Text) & " bytes: " & Text & Chr$(13) & Chr$(10)
  139. End Sub
  140. Sub IPPort1_Disconnected (StatusCode As Integer, Description As String)
  141. Me.MousePointer = 0
  142. If Description <> "OK" Then
  143.     MsgBox "Connection broken: " & Description
  144. End If
  145. End Sub
  146. Sub tHostAddress_KeyPress (KeyAscii As Integer)
  147. On Error GoTo DAR_Failed:
  148. If KeyAscii = 13 Then
  149.     KeyAscii = 0
  150.     IPPort1.HostAddress = tHostAddress.Text
  151.     tHostName.Text = IPPort1.HostName
  152. End If
  153. Exit Sub
  154. DAR_Failed:
  155.     MsgBox Error$
  156.     Exit Sub
  157. End Sub
  158. Sub tHostName_KeyPress (KeyAscii As Integer)
  159. On Error GoTo DNR_Failed:
  160. If KeyAscii = 13 Then
  161.     KeyAscii = 0
  162.     IPPort1.HostName = tHostName.Text
  163.     tHostAddress.Text = IPPort1.HostAddress
  164. End If
  165. Exit Sub
  166. DNR_Failed:
  167.     MsgBox Error$
  168.     Exit Sub
  169. End Sub
  170.